#include <stdio.h>
#include <ctype.h>
#define max_symbol_length 250

char symbol[max_symbol_length];

double get_atom_weight(char *c) {
  if (*c == 'C') return 12.01;
  else if (*c == 'H') return 1.008;
  else if (*c == 'O') return 16.00;
  else if (*c == 'N') return 14.01;
}

double get_symbol_weight(char *s) {
  double sum = 0, atom_weight;

  for ( ; *s != '\0'; s++) {
    atom_weight = get_atom_weight(s);
    if (isalpha(*(s + 1)) || *(s + 1) == '\0') {
      sum += atom_weight;
    } else {
      if (isdigit(*(s + 2))) {
        sum += atom_weight * ((*(s + 1) - '0') * 10);
        sum += atom_weight * (*(s + 2) - '0');
        s += 2;
      } else {
        sum += atom_weight * (*(s + 1) - '0');
        s++;
      }
    }
  }
  
  return sum;
}

int main() {
  int k;

  scanf("%d", &k);
  while (k--) {
    scanf("%s", symbol);
    printf("%.3f\n", get_symbol_weight(symbol));
  }

  return 0;
}
